﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Medianamik.Core;
using Medianamik.Core.Interfaces;
using Moq;
using NUnit.Framework;
using Medianamik.Core.Security;

namespace Medianamik.Tests.Unit.Medianamik.Core.Security
{
    [TestFixture]
    public class GroupTest
    {
        [Test]
        public void when_group_is_superadmins_all_groups_are_considered_child()
        {
            var parentGroup = new Group("", MedianamikGroups.SuperAdmins, null,"",0);
            var childGroup = new Group("", null);

            var isParent = parentGroup.IsParent(childGroup);

            Assert.That(isParent, Is.True);
        }

        [Test]
        public void when_group_is_a_direct_child_of_another_one_the_last_one_should_be_parent_of_the_first_one()
        {
            var parentId = Guid.NewGuid();
            var childGroup = new Group("", Guid.NewGuid(), parentId, "", 0);
            var parentGroup = new Group("", parentId, null, "", null);

            var isParent = parentGroup.IsParent(childGroup);

            Assert.That(isParent, Is.True);
        }

        [Test]
        public void when_group_is_a_indirect_child_of_another_one_the_last_one_should_be_parent_of_the_first_one()
        {
            var childGroup = new Group("", Guid.Empty, null,
                                       ".48849835-9843-43BC-B277-152D1D8775DE.4F1298A0-61D4-4B72-BADC-28094965B3D5.7C726242-3979-4BB3-A742-5FCC16A6BA17.E5556BF7-A41D-43A8-99DD-DA0AB9DB3A7B.F843ABF6-3030-4544-AF2B-76F6D8D18DE4.",
                                       0);
            var parentGroup = new Group("", new Guid("4f1298a0-61d4-4b72-badc-28094965b3d5"), null, "", 0);

            var isParent = parentGroup.IsParent(childGroup);

            Assert.That(isParent, Is.True);
        }
    }
}